<script lang="ts" setup>
import { columns, searchFormSchema } from './importFail.data'
import { useI18n } from '@/hooks/web/useI18n'
import { useMessage } from '@/hooks/web/useMessage'
import { IconEnum } from '@/enums/appEnum'
import { BasicTable, TableAction, useTable } from '@/components/Table'
import { deleteImportFail, getImportFailPage } from '@/api/wages/importfail'

defineOptions({ name: 'ImportFail' })

const props = defineProps({
  historyId: {
    type: Number,
  },
})

const { t } = useI18n()
const { createMessage } = useMessage()

const [registerTable, { reload }] = useTable({
  title: 'excel导入失败记录列表',
  api: () => getImportFailPage({ historyId: props.historyId }),
  columns,
  formConfig: { labelWidth: 120, schemas: searchFormSchema },
  useSearchForm: false,
  showTableSetting: true,
  actionColumn: {
    width: 140,
    title: t('common.action'),
    dataIndex: 'action',
    fixed: 'right',
  },
})

/* async function handleExport() {
  createConfirm({
    title: t('common.exportTitle'),
    iconType: 'warning',
    content: t('common.exportMessage'),
    async onOk() {
      await exportImportFail(getForm().getFieldsValue())
      createMessage.success(t('common.exportSuccessText'))
    },
  })
} */

async function handleDelete(record: Recordable) {
  await deleteImportFail(record.id)
  createMessage.success(t('common.delSuccessText'))
  reload()
}
</script>

<template>
  <div>
    <BasicTable @register="registerTable">
      <template #toolbar>
        <!--        <a-button type="primary" v-auth="['wages:import-fail:create']" :preIcon="IconEnum.ADD" @click="handleCreate">
          {{ t('action.create') }}
        </a-button>
        <a-button v-auth="['wages:import-fail:export']" :preIcon="IconEnum.EXPORT" @click="handleExport">
          {{ t('action.export') }}
        </a-button>
 -->
      </template>
      <template #bodyCell="{ column, record }">
        <template v-if="column.key === 'action'">
          <TableAction
            :actions="[
              {
                icon: IconEnum.DELETE,
                danger: true,
                label: t('action.delete'),
                auth: 'wages:import-fail:delete',
                popConfirm: {
                  title: t('common.delMessage'),
                  placement: 'left',
                  confirm: handleDelete.bind(null, record),
                },
              },
            ]"
          />
        </template>
      </template>
    </BasicTable>
  </div>
</template>
